home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / game / shoot / Fme.lha / Fme / Source / gels.c < prev    next >
C/C++ Source or Header  |  1988-08-15  |  5KB  |  164 lines

  1. #include "exec/types.h"
  2. #include "exec/memory.h"
  3. #include "graphics/gfxbase.h"
  4. #include "graphics/gels.h"
  5. #include "intuition/intuition.h"
  6. #include "functions.h"
  7.  
  8. MakeGelsInfo(rp)
  9. struct RastPort *rp;
  10. {
  11.     struct GelsInfo *g;
  12.     struct VSprite *HeadSprite, *TailSprite;
  13.  
  14.     g = (struct GelsInfo *)AllocMem(sizeof(struct GelsInfo),
  15.         MEMF_PUBLIC | MEMF_CLEAR);
  16.     rp->GelsInfo = g;
  17.  
  18.     g->sprRsrvd = 0x00;
  19.     g->nextLine = (WORD *)AllocMem(8 * sizeof(WORD),
  20.         MEMF_PUBLIC | MEMF_CLEAR);
  21.     g->lastColor = (WORD **)AllocMem(8 * sizeof(LONG),
  22.         MEMF_PUBLIC | MEMF_CLEAR);
  23.     g->collHandler = AllocMem(sizeof(struct
  24.        collTable),MEMF_PUBLIC | MEMF_CLEAR);
  25.     g->leftmost = 0;
  26.     g->rightmost = rp->BitMap->BytesPerRow * 8 - 1;
  27.     g->topmost = 0;
  28.     g->bottommost = rp->BitMap->Rows - 1;
  29.  
  30.     HeadSprite = (struct VSprite *)AllocMem(sizeof(struct VSprite),
  31.         MEMF_PUBLIC | MEMF_CLEAR);
  32.     TailSprite = (struct VSprite *)AllocMem(sizeof(struct VSprite),
  33.         MEMF_PUBLIC | MEMF_CLEAR);
  34.     InitGels(HeadSprite, TailSprite, g);
  35. }
  36.  
  37.  
  38. /* ======================================================================== */
  39. /* ==== DeleteGelsInfo ==================================================== */
  40. /* ======================================================================== */
  41.  
  42. DeleteGelsInfo(g)
  43. struct GelsInfo *g;
  44. {
  45.     if(g)
  46.     {
  47.         if(g->nextLine)FreeMem(g->nextLine, 8 * sizeof(WORD));
  48.         if(g->lastColor)FreeMem(g->lastColor, 8 * sizeof(LONG));
  49.         if(g->collHandler)FreeMem(g->collHandler,
  50.               sizeof(struct collTable));
  51.         if(g->gelHead)FreeMem(g->gelHead, sizeof(struct VSprite));
  52.         if(g->gelTail)FreeMem(g->gelTail, sizeof(struct VSprite));
  53.  
  54.         FreeMem(g, sizeof(struct GelsInfo));
  55.     }
  56. }
  57.  
  58.  
  59. /* ======================================================================== */
  60. /* ==== MakeVSprite ======================================================= */
  61. /* ======================================================================== */
  62.  
  63. struct VSprite *
  64. MakeVSprite(x, y, vsheight, vswidth, vsdepth, vsimage, vscolors)
  65. WORD x, y;
  66. WORD vsheight, vswidth, vsdepth;
  67. WORD *vsimage;
  68. WORD *vscolors;
  69. {
  70.     int i;
  71.     struct VSprite *vs;
  72.  
  73.     vs = (struct VSprite *)AllocMem(sizeof(struct VSprite),
  74.         MEMF_PUBLIC | MEMF_CLEAR);
  75.  
  76.     vs->Flags = VSPRITE;
  77.     vs->X = x;
  78.     vs->Y = y;
  79.     vs->Height = vsheight;
  80.     vs->Width = vswidth;
  81.     vs->Depth = vsdepth;
  82.     vs->ImageData = (WORD *)AllocMem(vsheight * vswidth * vsdepth *
  83.         sizeof(WORD), MEMF_CHIP);
  84.     for(i = 0; i < (vsheight * vswidth * vsdepth); i++)
  85.         vs->ImageData[i] = vsimage[i];
  86.  
  87.     vs->SprColors = vscolors;
  88.  
  89.     return(vs);
  90. }
  91.  
  92.  
  93. /* ======================================================================== */
  94. /* ==== DeleteVSprite ===================================================== */
  95. /* ======================================================================== */
  96.  
  97. DeleteVSprite(vs)
  98. struct VSprite *vs;
  99. {
  100.     if(vs)
  101.     {
  102.         if(vs->VSBob)
  103.         {
  104.             RemBob(vs->VSBob);
  105.             if(vs->VSBob->SaveBuffer)FreeMem(vs->VSBob->SaveBuffer,
  106.                 vs->Height * vs->Width * vs->Depth * sizeof(WORD));
  107.             FreeMem(vs->VSBob, sizeof(struct Bob));
  108.         }
  109.  
  110.         RemVSprite(vs);
  111.  
  112.         if(vs->ImageData)FreeMem(vs->ImageData,
  113.             vs->Height * vs->Width * vs->Depth * sizeof(WORD));
  114.         if(vs->BorderLine)FreeMem(vs->BorderLine,
  115.             vs->Width * sizeof(WORD));
  116.         if(vs->CollMask) FreeMem(vs->CollMask,
  117.             vs->Height * vs->Width * sizeof(WORD));
  118.  
  119.         FreeMem(vs, sizeof(struct VSprite));
  120.     }
  121. }
  122.  
  123.  
  124. /* ======================================================================== */
  125. /* ==== MakeBob =========================================================== */
  126. /* ======================================================================== */
  127.  
  128. struct VSprite *
  129. MakeBob(x, y, bheight, bwidth, bdepth, bimage, pp, poo)
  130. WORD x, y;
  131. WORD bheight, bwidth, bdepth;
  132. WORD *bimage;
  133. BYTE pp, poo;
  134. {
  135.     struct Bob *b;
  136.     struct VSprite *v;
  137.  
  138.     v = MakeVSprite(x, y, bheight, bwidth, bdepth, bimage, NULL);
  139.     b = (struct Bob *)AllocMem(sizeof(struct Bob),
  140.         MEMF_PUBLIC | MEMF_CLEAR);
  141.     v->VSBob = b;
  142.     b->BobVSprite = v;
  143.  
  144.     v->PlanePick = pp;
  145.     v->PlaneOnOff = poo;
  146.     v->Flags = OVERLAY | SAVEBACK;
  147.  
  148.     v->BorderLine = (WORD *)AllocMem((bwidth * sizeof(WORD)),
  149.         MEMF_PUBLIC | MEMF_CLEAR);
  150.     v->CollMask = (WORD *)AllocMem((sizeof(WORD) * bheight * bwidth),
  151.         MEMF_CHIP | MEMF_CLEAR);
  152.  
  153.     b->SaveBuffer = (WORD *)AllocMem(bheight * bwidth * bdepth *
  154.         sizeof(WORD), MEMF_CHIP | MEMF_CLEAR);
  155.     b->ImageShadow = v->CollMask;
  156.  
  157.     InitMasks(v);
  158.  
  159.     return(v);
  160. }
  161.  
  162.  
  163.  
  164.